using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using BreukenWebsite.Models;

namespace BreukenWebsite.Controllers
{
    public class ResultaatController : Controller
    {
        BreukenRepository breukenRepository = new BreukenRepository();

        //
        // GET: /Resultaat/
        [Authorize(Roles = "admin")]
        public ActionResult Index()
             
        {
            var leerlingen = breukenRepository.FindAllLeerlingen();
            return View("Index", leerlingen);
        }

        //
        // GET: /Resultaat/Details/5
        [Authorize(Roles = "admin")]
        public ActionResult Resultaat(int id)
        {
            LeerlingOpdracht leerlingopdracht = breukenRepository.GetLeerlingOpdracht(id);
            if (leerlingopdracht == null)
            {
                return View("NotFound");
            }
            else
            {
                var leerlingopdrachtdetails = breukenRepository.FindAllLeerlingOpdrachtDetailsByLeerlingAndOpdracht(leerlingopdracht.leerlingID,leerlingopdracht.opdrachtID);
                return View("Resultaat", leerlingopdrachtdetails);
            }
        }

        [Authorize(Roles = "admin")]
        public ActionResult Bekijk(int id)
        {
            var leerlingopdrachten = breukenRepository.GetLeerlingOpdrachtenByLeerling(id);

            var opdrachten = breukenRepository.OpdrachtenByLeerling(id);
            if (opdrachten == null)
            {
                return View("NotFound");
            }
            else
            {
                ViewData["LeerlingOpdrachten"] = leerlingopdrachten;
                return View("Bekijk", opdrachten);
            }
        }



        //
        // GET: /Resultaat/Create
        [Authorize(Roles = "admin")]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Resultaat/Create
        [Authorize(Roles = "admin")]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        /*
        //
        // GET: /Resultaat/Edit/5
        [Authorize(Roles = "admin")]
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Resultaat/Edit/5
        [Authorize(Roles = "admin")]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }*/
    }
}
